<template>
  <!-- 消防信息 -->
  <div>
    <public-modal
      :footer="false"
      :publicVisible="publicVisible"
      cancelContext="拒绝"
      confirmContext="通过"
      modalStyle="detailModal"
      title="联防队员详情"
      width="880px"
      @cancel="cancel"
    >
      <div slot="content">
        <div class="common-title" style="padding-top: 0">
          <div class="icon"></div>
          <div class="content">身份信息</div>
        </div>

        <table>
          <tr>
            <td class="td-label">姓名</td>
            <td class="td-value w-290">{{ record.personName || '暂无' }}</td>
            <td class="td-label" rowspan="4">头像</td>
            <td class="td-value w-290" rowspan="4">
              <img
                :id="record.personImage"
                :data-original="imgPrefix + record.personImage"
                :src="imgPrefix + record.personImage"
                class="cursor"
                style="width: 1.34rem; height: 1.55rem"
                @click="werImg(record.personImage)"
              />
            </td>
          </tr>
          <tr>
            <td class="td-label">性别</td>
            <td class="td-value w-290">{{ record.sex == 1 ? '男' : '女' }}</td>
          </tr>
          <tr>
            <td class="td-label">年龄</td>
            <td class="td-value w-290">{{ calc_age(record.birth) }}</td>
          </tr>
          <tr>
            <td class="td-label">联系方式</td>
            <td class="td-value w-290">{{ record.mobile }}</td>
          </tr>
          <tr>
            <td class="td-label">身份证号</td>
            <td class="td-value w-290">{{ record.idCard }}</td>
            <td class="td-label">证件照片</td>
            <td class="td-value w-290 click-style">
              <span @click="werImg(record.idCardImage)">查看</span>
              <img
                :id="record.idCardImage"
                :data-original="imgPrefix + record.idCardImage"
                :src="imgPrefix + record.idCardImage"
                style="display: none"
              />
            </td>
          </tr>
          <tr>
            <td class="td-label">户籍地址</td>
            <td class="td-value" colspan="3">{{ record.residenceDetail || '暂无' }}</td>
          </tr>
          <tr>
            <td class="td-label">现居地址</td>
            <td class="td-value" colspan="3">{{ record.addressDetail || '暂无' }}</td>
          </tr>
        </table>

        <div class="common-title" style="padding-top: 0">
          <div class="icon"></div>
          <div class="content">基本信息</div>
        </div>

        <table>
          <tr>
            <td class="td-label">政治面貌</td>
            <td class="td-value w-150">{{ record.politicalOutlook || '暂无' }}</td>
            <td class="td-label">民 族</td>
            <td class="td-value w-150">{{ record.race || '暂无' }}</td>
            <td class="td-label">籍 贯</td>
            <td class="td-value w-150">{{ record.nativePlace || '暂无' }}</td>
          </tr>
          <tr>
            <td class="td-label">身 高</td>
            <td class="td-value w-150">{{ record.height || '暂无' }}</td>
            <td class="td-label">健康状况</td>
            <td class="td-value w-150">{{ record.healthStatus || '暂无' }}</td>
            <td class="td-label">婚姻状况</td>
            <td class="td-value w-150">{{ record.maritalStatus || '暂无' }}</td>
          </tr>
          <tr>
            <td class="td-label">学 历</td>
            <td class="td-value w-150">{{ record.education || '暂无' }}</td>
            <td class="td-label">专 业</td>
            <td class="td-value w-150" colspan="3">{{ record.workUnit || '暂无' }}</td>
          </tr>
        </table>

        <div class="common-title" style="padding-top: 0">
          <div class="icon"></div>
          <div class="content">工作信息</div>
        </div>

        <table>
          <tr>
            <td class="td-label">培训机构名称</td>
            <td class="td-value w-290">
              <a-tooltip placement="topLeft">
                <template slot="title">
                  <span> {{ record.trainingInstitutions || '暂无' }} </span>
                </template>
                {{ record.trainingInstitutions || '暂无' }}
              </a-tooltip>
            </td>
            <td class="td-label">培训时间</td>
            <td class="td-value w-290">
              {{ split_time_at_space(record.trainingStartTime) || '暂无' }}
              - {{ split_time_at_space(record.trainingEndTime) || '暂无' }}
            </td>
          </tr>
          <tr>
            <td class="td-label">执勤编号</td>
            <td class="td-value w-290">
              <a-tooltip placement="topLeft">
                <template slot="title">
                  <span> {{ record.dutyNumber || '暂无' }} </span>
                </template>
                {{ record.dutyNumber || '暂无' }}
              </a-tooltip>
            </td>
            <td class="td-label">发证机关</td>
            <td class="td-value w-290">
              <a-tooltip placement="topLeft">
                <template slot="title">
                  <span> {{ record.issuingUnit || '暂无' }} </span>
                </template>
                {{ record.issuingUnit || '暂无' }}
              </a-tooltip>
            </td>
          </tr>
          <tr>
            <td class="td-label">工作单位</td>
            <td class="td-value w-290">
              <a-tooltip placement="topLeft">
                <template slot="title">
                  <span> {{ record.workUnit || '暂无' }} </span>
                </template>
                {{ record.workUnit || '暂无' }}
              </a-tooltip>
            </td>
            <td class="td-label">录用时间</td>
            <td class="td-value w-290">{{ split_time_at_space(record.employmentTime) || '暂无' }}</td>
          </tr>
        </table>
      </div>

      <div slot="footer"></div>
    </public-modal>
  </div>
</template>
<script>
import Viewer from 'viewerjs'
import 'viewerjs/dist/viewer.css'
import publicModal from '@/components/publicModal'
import { getAction } from '@/api/manage'
import { findEnableDictItemsbyCode } from '@/api/api'
export default {
  name: 'detailModal',
  components: { publicModal },
  data() {
    return {
      imgPrefix: '',
      record: {},
      publicVisible: false,
    }
  },

  methods: {
    werImg(id) {
      const ViewerDom = document.getElementById(id)
      const viewer = new Viewer(ViewerDom, {
        toolbar: false,
        button: false,
        navbar: false,
        title: false,
        zIndex: '9999',
        url: 'data-original',
        hide: function () {
          viewer.destroy()
        },
      })
      viewer.show()
    },

    show(record) {
      this.record = record
      console.log(record, '1')
      this.get_dict()
      this.publicVisible = true
    },

    async get_dict() {
      let res = await findEnableDictItemsbyCode({ code: 'static_server' })
      this.imgPrefix = res.result[0].value
    },

    async get_company_duty_person_detail(companyId) {
      let { result } = await getAction('/company/duty_person/detail', { companyId })
      this.company_duty_person_detail = result
    },

    calc_age(birthdate) {
      const birthDate = new Date(birthdate)
      const currentDate = new Date()

      let age = currentDate.getFullYear() - birthDate.getFullYear()

      // 检查是否已过生日
      if (
        currentDate.getMonth() < birthDate.getMonth() ||
        (currentDate.getMonth() === birthDate.getMonth() && currentDate.getDate() < birthDate.getDate())
      ) {
        age--
      }

      return age
    },

    split_time_at_space(time) {
      if (!time) return
      return time.split(' ')[0]
    },

    cancel(target) {
      this.publicVisible = false
    },
  },
}
</script>

<style lang="less" scoped>
table {
  font-family: PingFang SC-Medium, PingFang SC;
  border-collapse: collapse;
  font-weight: 500;
  margin-top: 0.12rem;
  margin-bottom: 0.22rem;
}

tr {
  width: 100%;
  height: 0.46rem;
  font-size: 0.14rem;
}

.td-label {
  background: var(--theme-modal-label-bg);
  border: 0.01rem solid var(--theme-input-border);
  color: var(--theme-tab-text-color);
  width: 1.2rem;
  text-align: center;
}

.td-value {
  background: var(--theme-container-bg);
  border: 0.01rem solid var(--theme-input-border);
  color: var(--theme-modal-label-value-color);
  padding-left: 0.25rem;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.click-style {
  color: #47e829;
  cursor: pointer;
}

.w-290 {
  width: 2.9rem;
  min-width: 2.9rem;
}

.w-150 {
  width: 1.5rem;
  min-width: 1.5rem;
}
</style>

<style lang="less" scoped>
/deep/ .modalCotent {
  padding: 20px 40px;
  border-radius: 0 0 4px 4px;
}
</style>
